<?php

require_once('include.php');

$query = 'SELECT * FROM algorithm';
$algorithms = $GLOBALS['db']->fetchAll($query);

$query = 'SELECT id, title, number_of_vertices, number_of_edges FROM graph';
$graphs = $GLOBALS['db']->fetchAll($query);

$results = array();
foreach ($graphs as $graph) {
	$alg = array();
	foreach ($algorithms as $algorithm) {
		$query = 'SELECT MIN(found_chromatic_number) AS minimum FROM chromatic_number WHERE algorithm = ' . $algorithm['id'] . ' AND graph = ' . $graph['id'];
		$res = $GLOBALS['db']->fetchFirst($query);
		$minimum = $res['minimum'];
		
		$query = 'SELECT MAX(found_chromatic_number) AS maximum FROM chromatic_number WHERE algorithm = ' . $algorithm['id'] . ' AND graph = ' . $graph['id'];
		$res = $GLOBALS['db']->fetchFirst($query);
		$maximum = $res['maximum'];
		
		$row = array('minimum' => $minimum, 'maximum' => $maximum);
		$alg[$algorithm['title']] = $row;
	}
	$results[$graph['title']] = $alg;
}

$output = '<table border=1><tr><td>Graf</td><td colspan="2">Brelaz</td><td colspan="2">Minimum first</td><td colspan="2">Lulco</td><td colspan="2">Brelaz With Random</td>';
foreach ($results as $graph => $stats) {
	$output .= '<tr><td>' . $graph . '</td>';
	foreach ($stats as $stat) {
		$output .= '<td>' . $stat['minimum'] . '</td><td>' . $stat['maximum'] . '</td>';
	}
	$output .= '</tr>';
}
echo $output .= '<table>';

?>